''' 函数重写 '''


class MyNumber():
    def __init__(self,data):
        self.data = data

    def __str__(self):
        return "str对象数值：%d" % self.data

    def __int__(self):
        # 重写超级类object中提供的int()内建函数
        # 返回整型
        return self.data

    def __float__(self):
        return self.data

    # def __bool__(self):
    #     if self.data >=50:
    #         return True
    #     else:
    #         return False

    def __len__(self):
        # num=0
        # for i in self.data:
        #     num+=1
        return len(self.data)


number = MyNumber(50)
number2 = MyNumber(5.6)
number3 = MyNumber([1,2,12])
print(str(number))
print(type(int(number)))
print(int(number))
print(type(float(number2)))
print(float(number2))

# 当没有重写bool，但重写了len将会优先调用重写的len
# print(bool(number))
print(len('number2'))
print(bool(number3))
